'use strict';

const mongoose = require('mongoose'),
    advertModel = mongoose.model('advert');

module.exports = {
    insertOne: insertOne,
    updateStatus : updateStatus,
    getBystatus: getBystatus,
    getByNotstatus: getByNotstatus,
    getOnOrdown: getOnOrdown
}

function insertOne(advert, callback) {
    console.log(advert)
    advertModel.create(advert,function(error, data){
        callback(null,data);
    });
}

function updateStatus(advert, callback){
    advert.reviewTime = new Date();
    advertModel.updateOne({'_id':advert._id}, advert, function(error, data){
        callback(null,data);
    });
}

function getBystatus(status, callback){
    advertModel.find({status:status},function(error, data){
        callback(null,data);
    });
}

function getByNotstatus(status, callback){
    advertModel.find({status:{$not: {$eq: status}}},function(error, data){
        callback(null,data);
    });
}

function getOnOrdown(callback){
    advertModel.find({status:{$in: ['1','3']}},function(error, data){
        callback(null,data);
    });
}